package sk.project.accounting.data.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sk.project.accounting.data.model.Company;

@Repository
public class CompanyDaoImpl implements CompanyDao{
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	public List<Company> getAllCompanies() {
		Session session = sessionFactory.getCurrentSession();		
		Criteria criteria = session.createCriteria(Company.class);
		List<Company> companies = criteria.list();
		return companies;
	}

	@SuppressWarnings("unchecked")
	public Company getCompanyById(int id) {
		Session session = sessionFactory.getCurrentSession();	
		Company company = (Company)session.get(Company.class, id);
		return company;
	}

	public int addCompany(Company company){		
		Session session = sessionFactory.getCurrentSession();
		int id = (Integer) session.save(company);
		return id;
	}	

}

